import React from 'react';
import { Button, Form, Input,Select,InputNumber,message} from 'antd';
import { useNavigate,useLocation} from 'react-router-dom';
import axios from '../../../../utils/myAixos'
import "./schedule.scss"
const Schedule=()=>{
    let location = useLocation();
    console.log(location)
    //保存
    const navigate = useNavigate();
    const handleBack=()=>{
        // navigate(-1)
    }
    //排期
      const onFinish = (values) => {
        console.log('Finish:', values);
        axios({
          url: '/yueadds',
          method: 'post',
          data:{
              v_classname:location.state.c_name,
              v_teacher:location.state.c_teacher,
              v_name:values.v_name,
              v_number:location.state.c_number,
              v_address:values. v_address,
              v_time:values.v_time
          }
      }).then(res => {
          console.log('添加结果', res)
          if (res.status === 200) {
              message.success('排课成功')
          } else {
              message.error('排课失败')
          }
      }).catch(err => {
          console.log('排课失败的结果', err)
      })
    };
    return(
        //排课信息
        <div>
          <div className={"box"}>
          <header className={"head"}>
            排课信息
          </header>
            {/* 表单 */}
          <div  className={"content"}>
          <Form
                  labelCol={{ span: 8 }}
                  wrapperCol={{ span: 16 }}
                  style={{ maxWidth: 600 }}
                  onFinish={onFinish}
                  autoComplete="off"                  
                >
                    <Form.Item
                        label="课程名称"
                        name="v_classname"
                    >
                        <Input placeholder={location.state.c_name} />
                    </Form.Item>
                    <Form.Item
                        name="teacher"
                        label="课程教练"
                    >
                        <Select
                            defaultValue="请选择课程教练"
                            style={{
                                width: 120,
                                float:"left"
                            }}
                            options={[
                                {
                                    value: '从有',
                                    label: '从有',
                                }
                            ]}
                        />

                    </Form.Item>              
                    <Form.Item
                        label="场馆"
                        name="v_name"
                    >
                        <Select
                            defaultValue="请选择课程场馆"
                            style={{
                                width: 120,
                                float:"left"
                            }}
                            options={[
                                {
                                    value: '大都会健身馆',
                                    label: '大都会健身馆',
                                },
                                {
                                    value: '硬汉健身馆',
                                    label: '硬汉健身馆',
                                },
                                {
                                    value: '足迹健身馆',
                                    label: '足迹健身馆',
                                }
                            ]}
                        />

                    </Form.Item>
                    <Form.Item
                        label="场地"
                        name="v_address"
                    >
                        <Select
                            defaultValue="请选择课程场地"
                            style={{
                                width: 120,
                                float:"left"
                            }}
                            options={[
                                {
                                    value: '北京市',
                                    label: '北京市',
                                },
                                {
                                    value: '福州',
                                    label: '福州',
                                },
                                {
                                    value: '成都',
                                    label: '成都',
                                }
                            ]}
                        />

                    </Form.Item>
                    <Form.Item label="可预约人数"
                        name="v_number"
                        rules={[{ required: true, message: '请输入可预约人数' }]}>
                            <InputNumber placeholder={location.state.c_number} style={{float:"left"}}/>
                    </Form.Item>
                    <Form.Item label="预约时间"
                        name="v_time"
                        rules={[{ required: true, message: '请输入预约时间' }]}>
                          <Select style={{width:'200px',float:"left"}}>
                            <option value="19:00 - 19:45">19:00 - 19:45</option>
                            <option value="9:00 - 19:45">19:00 - 19:45</option>
                            <option value="9:00 - 19:45">8:30 - 18:30</option>
                         </Select>         
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" htmlType="submit"  onClick={handleBack}>
                            保存
                        </Button>
                    </Form.Item>
                </Form>
          </div>
        </div>
        </div>
    )
}
export default Schedule